package com.study.common;

import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.AsymmetricAlgorithm;
import cn.hutool.crypto.asymmetric.AsymmetricCrypto;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.study.common.entity.Entity;
import com.study.common.utils.RSAEncryptUtil;
import sun.misc.BASE64Decoder;

import java.io.IOException;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Arrays;
import java.util.List;

/**
 * @description: some desc
 * @author: LChuang
 * @date: 2023/9/18 16:13
 */
public class Test {

    private static final String LOCAL_CODE = "HN_TECHNOLOGY";

    private static final String MARK = "HN_AND_PC";

    public static void main(String[] args) {
        System.out.println("68F648C5910509DE".hashCode());
        System.out.println(System.currentTimeMillis());
    }


    public void decode(){
        Entity entity = new Entity("jack", 18);

        AsymmetricCrypto asymmetricCrypto = new AsymmetricCrypto("RSA", RSAEncryptUtil.getRSAPrivateKeyByBase64(LOCAL_CODE),
                RSAEncryptUtil.getRSAPublicKeyByBase64(LOCAL_CODE));
        String encrypt = asymmetricCrypto.encryptBase64(JSON.toJSONString(entity), KeyType.PublicKey);
        System.out.println(encrypt);
        String decrypt = asymmetricCrypto.decryptStr(encrypt, KeyType.PrivateKey);
        Entity parseObject = JSONObject.parseObject(decrypt, Entity.class);
        System.out.println(decrypt);
        System.out.println(parseObject);
    }


}
